// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
// import VueResource from 'vue-resource';
// import VueScroller from 'vue-scroller';
// import VueLazyLoad from 'vue-lazyload';
require('es6-promise').polyfill()
// import './lib/css/animate.css';

import { ToastPlugin,AlertPlugin } from 'vux'
import Vuex from 'vuex'
// import store from './vuex/store.js'
// 环境变量为0时要注释掉[
// import env from './api/_env.js'
// import _axios from './api/_axios.js'
// Vue.prototype.$axios = _axios;
// ］
import user from './api/user.js'
import axios from './api/_axios.js'

var openid = '',
    nick = '',
    username = '',
    head = '',
    role = '',
    mch_id = 0,
    mch_name = '',
    type = "31,32,33"

if(!document.querySelector("#name") || document.querySelector("#name").innerHTML == ""){
    openid = "opxwxw9i2-AtcYCNqY6YNmu5ugkg"
    nick = "北京世纪天成有限公司"
    username = ""
    head = "http://wx.qlogo.cn/mmopen/vi_32/r9iaYia3nDPw4JN675C99UXSyssWBuNZnNp7abasd1lkB5tkgODbxWKibib1mzg86Jn08NyxafTc9lia5tKHpeVic06g/0"
    mch_id = 1
    mch_name = "1912"
    role = type
}else{
    var userInfo = JSON.parse(document.querySelector("#name").innerHTML)
    openid = userInfo.openid
    username = userInfo.username
    nick = userInfo.nickname
    head = userInfo.headimgurl
    mch_id = userInfo.mch_id
    mch_name = userInfo.mch_name
    role = userInfo.role
    // console.log(userInfo)
}
user.init({
    openid,nick,mch_id,mch_name,head,usertype:role,username
})
console.log('userinfo='+user.userinfo)
// Vue.use(axios)
Vue.prototype.$axios = axios
Vue.use(Vuex)
Vue.use(ToastPlugin)
Vue.use(AlertPlugin)
// Vue.config.productionTip = false;
Vue.use(VueRouter);
// Vue.use(VueResource);
// Vue.use(VueScroller);
// Vue.use(VueLazyLoad);
FastClick.attach(document.body)
/* eslint-disable no-new */

let store = new Vuex.Store({})

store.registerModule('vux', {
  state: {
    demoScrollTop: 0,
    isLoading: false,
    direction: 'forward'
  },
  mutations: {
    updateDemoPosition (state, payload) {
      state.demoScrollTop = payload.top
    },
    updateLoadingStatus (state, payload) {
      state.isLoading = payload.isLoading
    },
    updateDirection (state, payload) {
      state.direction = payload.direction
    }
  },
  actions: {
    updateDemoPosition ({commit}, top) {
      commit({type: 'updateDemoPosition', top: top})
    }
  }
})

Vue.use(store)

new Vue({
  el: '#app',
  template: '<App/>',
  components: { App,store }
});

